<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />

    <title>代码生成</title>
    <meta name="keywords" content="代码生成" />
    <meta name="description" content="代码生成" />
    <link rel="shortcut icon" href="favicon.ico" />

    <!-- 引入公共css -->
	<#include "/inc/header.ftl"/>
</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="page-title-box">
                <p class="page-title">
                    修改模板
                </p>
            </div>
        </div>
    </div>
    <div class="main">
        <div class="main-padding">
            <div class="ibox-content">
                <form class="form-horizontal m-t" id="signupForm">
                    <input type="hidden" name="templateId" id="templateId" value="${template.id!''}">

                    <div class="form-group">
                        <label class="col-sm-3 control-label">模板名称：</label>
                        <div class="col-sm-8">
                            <input id="name" name="name" class="form-control" value="${template.name!''}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">模板路径：</label>
                        <div class="col-sm-8">
                            <input id="path" name="path" class="form-control"  value="${template.path!''}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">文件名称：</label>
                        <div class="col-sm-8">
                            <input id="fileName" name="fileName" class="form-control" value="${template.fileName!''}">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">状态：</label>
                        <div class="col-sm-8">
                            <div class="switch">
                                <div class="onoffswitch margin-top-7">
                                    <input type="checkbox" <#if template.status == 1>checked</#if> class="onoffswitch-checkbox" id="status" name="status">
                                    <label class="onoffswitch-label" for="status">
                                        <span class="onoffswitch-inner"></span>
                                        <span class="onoffswitch-switch"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">文件路径：</label>
                        <div class="col-sm-8">
                            <select id="filePath" name="filePath"  class="form-control">
                                <option value="java" <#if template.filePath == "java">selected</#if>>java</option>
                                <option value="resources" <#if template.filePath == "resources">selected</#if>>resources</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">生成方式：</label>
                        <div class="col-sm-8">
                            <select id="genWay" name="genWay"  class="form-control">
                                <option value="1" <#if template.genWay == 1>selected</#if>>所有表</option>
                                <option value="2" <#if template.genWay == 2>selected</#if>>单个文件</option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-3 control-label">模板内容：</label>
                        <div class="col-sm-8">
                        	<input type="hidden" id="content" value="${template.content!''}">
                        	<input type="hidden" id="type" value="${template.type!''}">
                            <script id="editor" type="text/plain" style="width:1024px;height:500px;"></script>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-sm-8 col-sm-offset-3">
                        	<button class="btn btn-primary" type="button" id="modifyTemplate">提交</button>
                            <a class="btn btn-default" href="/auto/code/template/list">返回</a>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<!-- 引入公共js -->
<#include "/inc/footer.ftl"/>
<script type="text/javascript" charset="utf-8" src="/static/plugins/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="/static/plugins/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="/static/plugins/ueditor/lang/zh-cn/zh-cn.js"></script>

<!-- Page-Level Scripts -->
<script>
    $(document).ready(function() {
    	//实例化编辑器
   		var ue = UE.getEditor('editor', {
			toolbars: [
		        ['fullscreen','insertcode', 'preview']
		    ],
		    autoHeightEnabled: true,
		    autoFloatEnabled: true,
		    serverUrl:""
		});
		
		ue.ready(function() {
			var type = $('#type').val();
			var cls = "brush:" + type + ";toolbar:false";
	    	ue.setContent("<pre class=" + cls +">" + $("#content").val() + "</pre>");
	 	});
		    
        $("#modifyTemplate").on("click", function(){
            var name = $("#name").val();
            var path = $("#path").val();
            var fileName = $("#fileName").val();
			var status = $("#status").prop("checked") == true?1:2;
			var content = UE.getEditor('editor').getPlainTxt();
			var groupId = $("#groupId").val();
            var type = $("#edui4").text();
            var id = $("#templateId").val();
			
			if(name == "" || path == "" || fileName == "" || content == ""){
            	parent.layer.alert("请完善信息!");
            	return;
            }
			
            $.ajax({
                url : '/auto/code/template/modify',
                type : 'POST',
                data : {
                	id:id,
                    name:name,
                    path:path,
                    fileName:fileName,
                    status:status,
                    groupId:groupId,
                    content:content,
                    type:type,
                    filePath: $("#filePath").val(),
                    genWay : $("#genWay").val()
                },
                dataType : 'JSON',
                success : function(data) {
                    if(data.status == "200"){
                        parent.layer.alert("修改成功!");
                        setTimeout(function () {
                            window.location.href = "/auto/code/template/list";
                        },500)
                    }else{
                        parent.layer.alert("状态获取失败!");
                    }
                },
                error : function(result) {
                    parent.layer.alert("发生错误！");
                }
            });
        });
    });
</script>
</body>
</html>


